package com.ruoyi.mapper;

import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.domain.Article;
import com.ruoyi.domain.vo.ArticleColumnVo;
import com.ruoyi.domain.vo.ArticleOriginDateVo;
import com.ruoyi.domain.vo.DeptArticleCountVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * artilceMapper接口
 *
 * @author ruoyi
 * @date 2025-01-16
 */
@Mapper
public interface ArticleMapper extends BaseMapper<Article>
{

    /**
     * 根据条件统计文章来源及数量
     */
    @Select("SELECT article_origin AS articleOrigin, COUNT(*) AS count FROM article " +
            "${ew.customSqlSegment} " +
            "AND article_origin IS NOT NULL AND article_origin != '' " +
            "GROUP BY article_origin " +
            "ORDER BY count DESC")
    List<ArticleOriginDateVo> selectArticleOriginDateList(@Param("ew") LambdaQueryWrapper<Article> wrapper);

    /**
     * 根据条件统计各部门及子部门文章数量
     */
    @Select("SELECT #{deptName} AS deptName, COUNT(*) AS count FROM article " +
            "WHERE ${ew.customSqlSegment} " +
            "AND article_origin IN (${originList})")
    DeptArticleCountVo selectDeptArticleCount(@Param("deptName") String deptName,
                                              @Param("ew") LambdaQueryWrapper<Article> wrapper,
                                              @Param("originList") String originList);


    /**
     * 根据auditId删除article
     */
    public int deleteArticleByAuditId(Long auditId);

    /**
     * 根据auditId更新article
     */

    public int updateToArticle(@RequestBody Article article);


    /**
     * 查询artilce列表(权限)
     */
    public List<Article> selectArticleListByRole(@Param("isAdmin") boolean isAdmin,@Param("article") Article article);


    /**
     * 查询artilce
     *
     * @param articleId artilce主键
     * @return artilce
     */
    public Article selectArticleByArticleId(Long articleId);

    /**
     * 查询artilce列表
     *
     * @param article artilce
     * @return artilce集合
     */
    public List<Article> selectArticleList(Article article);

    /**
     * 新增artilce
     *
     * @param article artilce
     * @return 结果
     */
    public int insertArticle(Article article);

    /**
     * 修改artilce
     *
     * @param article artilce
     * @return 结果
     */
    public int updateArticle(Article article);

    /**
     * 删除artilce
     *
     * @param articleId artilce主键
     * @return 结果
     */
    public int deleteArticleByArticleId(Long articleId);

    /**
     * 批量删除artilce
     *
     * @param articleIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteArticleByArticleIds(Long[] articleIds);

    /**
     * 隐藏文章
     *
     * @param articleId 文章主键
     * @return 结果
     */
    public int hideArticle(Long articleId);

    /**
     * 显示文章
     *
     * @param articleId 文章主键
     * @return 结果
     */
    public int showArticle(Long articleId);

    /**
     * 批量隐藏文章
     *
     * @param articleIds 文章主键数组
     * @return 结果
     */
    public int batchHideArticle(Long[] articleIds);

    /**
     * 批量显示文章
     *
     * @param articleIds 文章主键数组
     * @return 结果
     */
    public int batchShowArticle(Long[] articleIds);
}
